package com.kili.cloud.shorturl.enumerate;

/**
 * @description: 是否删除类型枚举
 * @author: tom.liu
 * @date: 2019/6/16 23:01
 */
public enum IsDeletedEnum {
    /**
     * 未删除
     */
    NO(0,"no"),
    /**
     * 已删除
     */
    YES(1,"yes"),
    ;

    /**
     * 枚举值
     */
    private Integer code;
    /**
     * 枚举名
     */
    private String name;

    private IsDeletedEnum(Integer code, String name) {
        this.code = code;
        this.name = name;
    }

    /**
     * 通过code获取name
     * @author
     * @param code
     * @return
     */
    public static String getNameByCode(Integer code) {
        IsDeletedEnum target = getByCode(code);
        if (target == null) {
            return "";
        }
        return target.getName();
    }

    /**
     * 通过code获取枚举
     * @author
     * @param code
     * @return
     */
    public static IsDeletedEnum getByCode(Integer code) {
        if(code == null){
            return null;
        }
        for (IsDeletedEnum enumElement : values()) {
            if (enumElement.code.equals(code)) {
                return enumElement;
            }
        }
        return null;
    }

    public Integer getCode() {
        return code;
    }

    public String getName() {
        return name;
    }
}
